<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件绑定</title>
</head>
<body>
<!--ondbclick="addCity()"双击触发-->
<input type="text" placeholder="请输入内容：" id="txt">
<input type="button" value="点击添加"  onclick="addCity()">
<ul id="city">

</ul>

<script type="text/javascript">

    function addCity() {
        // 找到输入标签
        var txtTag = document.getElementById("txt");
        // 获取input框中的内容
        var cityString = txtTag.value;

        if (cityString !== ""){ // 非空才加 判断长度不为零同理 直接写if(cityString)也是没问题的

            // 创建标签
            var newTag = document.createElement("li");
            newTag.innerText=cityString;
            var ulTag = document.getElementById("city");
            ulTag.appendChild(newTag);
            //清空input框
            txtTag.value="";
        }else{
            alert("输入不能为空！")
        }
    }

</script>
</body>
</html>